﻿CREATE PROCEDURE [dbo].[Clientes_DevolverPorIdConDetalleDomiciliosTelefonos]

@IdCliente INT

AS

SELECT c.IdCliente, 
	c.IdRubroCliente, 
	c.IdTipoIva, 
	c.IdListaPrecioVenta, 
	c.IdVendedor, 
	c.Codigo, 
	c.Nombre, 
	c.Email, 
	c.SitioWeb, 
	c.DescuentoRecargo, 
	c.LimiteDeuda, 
	c.Cuit, 
	c.EstaEliminado
	FROM Clientes c
	WHERE c.IdCliente = @IdCliente
		
SELECT ISNULL(ctfp.IdClienteTipoFormaPago, 0) AS IdClienteTipoFormaPago,
	c1.IdCliente,
	tfp.IdTipoFormaPago,
	CAST((CASE WHEN ISNULL(ctfp.IdClienteTipoFormaPago, 0) = 0
			THEN 0
			ELSE 1 END) AS BIT) AS TienePermiso
	FROM Clientes c1
		CROSS JOIN TiposFormasPagos tfp
		INNER JOIN Clientes c2 
			ON c1.IdCliente = c2.IdCliente
		LEFT JOIN ClientesTiposFormasPagos ctfp 
			ON tfp.IdTipoFormaPago = ctfp.IdTipoFormaPago
			AND c1.IdCliente = ctfp.IdCliente
	WHERE c1.IdCliente = @IdCliente

SELECT cd.IdCliente,
	cd.Observacion,
	cd.Imagen
	FROM ClientesDetalles cd
	WHERE cd.IdCliente = @IdCliente

SELECT dc.IdDomicilioCliente,
	dc.IdCliente,
	dc.IdTipoDomicilio,
	dc.IdBarrio,
	dc.Calle,
	dc.Numero,
	dc.Piso,
	dc.Departamento,
	dc.Observacion
	FROM DomiciliosClientes dc
	WHERE dc.IdCliente = @IdCliente
	
SELECT tc.IdTelefonoCliente,
	tc.IdCliente,
	tc.IdTipoTelefono,
	tc.CodigoArea,
	tc.Numero,
	tc.Observacion
	FROM TelefonosClientes tc
	WHERE tc.IdCliente = @IdCliente
